package leetcode.code0554;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import leetcode.IDebug;

public class Solution implements IDebug {

	public int leastBricks(List<List<Integer>> wall) {

		Map<Integer, Integer> hash = new HashMap<>();
		int max = 0;
		for (List<Integer> list : wall) {
			int size = 0;
			for (Integer width : list) {
				size += width;
				hash.put(size, hash.getOrDefault(size, 0) + 1);
			}
			max = Math.max(max, size);
		}
		int ans = 0;
		for (Map.Entry<Integer, Integer> entry : hash.entrySet()) {
			if (entry.getKey() != max) {
				ans = Math.max(ans, entry.getValue());
			}
		}
		int total = wall.size();
		return total - ans;
	}

	@Override
	public void debug1() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug2() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug3() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug4() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}
